//转义
var REGEXP_SINGLE_QUOTE = /'/g;
var REGEXP_LT = /</g;
var REGEXP_GT = />/g;
var REGEXP_QUOTE = /"/g;
function escapeHtmls (html) {
  return html.replace(REGEXP_LT, '').replace(REGEXP_GT, '').replace(REGEXP_QUOTE, '').replace(REGEXP_SINGLE_QUOTE, '');
}

//输入数据转义
function filters(elem) {
	var value = $(elem).val();
	var html = filterXSS(value, {
		whiteList:          [],        // 白名单为空，表示过滤所有标签
		stripIgnoreTag:     true,      // 过滤所有非白名单标签的HTML
		safeAttrValue: true,
		escapeHtml:escapeHtmls
	});
	$(elem).val(html);
}

//扩展Date的format方法 
Date.prototype.format = function (format) { 
var o = { 
"M+": this.getMonth() + 1, 
"d+": this.getDate(), 
"h+": this.getHours(), 
"m+": this.getMinutes(), 
"s+": this.getSeconds(), 
"q+": Math.floor((this.getMonth() + 3) / 3), 
"S": this.getMilliseconds() 
} 
if (/(y+)/.test(format)) { 
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 
} 
for (var k in o) { 
if (new RegExp("(" + k + ")").test(format)) { 
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); 
} 
} 
return format; 
} 
/** 
*转换日期对象为日期字符串 
* @param date 日期对象 
* @param isFull 是否为完整的日期数据, 
* 为true时, 格式如"2000-03-05 01:05:04" 
* 为false时, 格式如 "2000-03-05" 
* @return 符合要求的日期字符串 
*/ 
function getSmpFormatDate(date, isFull) { 
var pattern = ""; 
if (isFull == true || isFull == undefined) { 
pattern = "yyyy-MM-dd hh:mm:ss"; 
} else { 
pattern = "yyyy-MM-dd"; 
} 
return getFormatDate(date, pattern); 
} 
/** 
*转换当前日期对象为日期字符串 
* @param date 日期对象 
* @param isFull 是否为完整的日期数据, 
* 为true时, 格式如"2000-03-05 01:05:04" 
* 为false时, 格式如 "2000-03-05" 
* @return 符合要求的日期字符串 
*/ 
function getSmpFormatNowDate(isFull) { 
return getSmpFormatDate(new Date(), isFull); 
} 
/** 
*转换long值为日期字符串 
* @param l long值 
* @param isFull 是否为完整的日期数据, 
* 为true时, 格式如"2000-03-05 01:05:04" 
* 为false时, 格式如 "2000-03-05" 
* @return 符合要求的日期字符串 
*/ 
function getSmpFormatDateByLong(l, isFull) { 
return getSmpFormatDate(new Date(l), isFull); 
} 
/** 
*转换long值为日期字符串 
* @param l long值 
* @param pattern 格式字符串,例如：yyyy-MM-dd hh:mm:ss 
* @return 符合要求的日期字符串 
*/ 
function getFormatDateByLong(l, pattern) { 
return getFormatDate(new Date(l), pattern); 
} 
/** 
*转换日期对象为日期字符串 
* @param l long值 
* @param pattern 格式字符串,例如：yyyy-MM-dd hh:mm:ss 
* @return 符合要求的日期字符串 
*/ 
function getFormatDate(date, pattern) { 
if (date == undefined) { 
date = new Date(); 
} 
if (pattern == undefined) { 
pattern = "yyyy-MM-dd hh:mm:ss"; 
} 
return date.format(pattern); 
} 

/**
 * 时间戳转yyyy-MM-dd
 * @param inputTime
 * @returns
 */
function formatDateTime(inputTime) {  
    var date = new Date(inputTime);
    var y = date.getFullYear();  
    var m = date.getMonth() + 1;  
    m = m < 10 ? ('0' + m) : m;  
    var d = date.getDate();  
    d = d < 10 ? ('0' + d) : d;  
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;  
    second = second < 10 ? ('0' + second) : second; 
    return y + '-' + m + '-' + d;  
   // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;  
};

$(function () {
"use strict";
/*$("#startTime").datetimepicker({
	format : 'yyyy-mm-dd',
	autoclose : true,
	todayBtn : true,
	language : 'zh-CN' ,
	minView : 'month'
});
$("#endTime").datetimepicker({
	format : 'yyyy-mm-dd',
	autoclose : true,
	todayBtn : true,
	language : 'zh-CN',
	minView : 'month'
});
if(confirm) {
	$.messager.model = { 
    ok:{ text: "确定", classed: 'btn-default' },
    cancel: { text: "取消", classed: 'btn-error' }
    };
}*/
});

$.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return  decodeURI(r[2]); return null;
}

//数组去重
Array.prototype.unique = function(){
	 this.sort(); //先排序
	 var res = [this[0]];
	 for(var i = 1; i < this.length; i++){
		 if(this[i] !== res[res.length - 1]){
			 res.push(this[i]);
	  	}
	 }
	 return res;
}

//数组去重
function unique(arr) {
    var result = [], isRepeated;
    for (var i = 0;i<arr.length;i++) {
        isRepeated = false;
        for (var j = 0;j<result.length;j++) {
            if (arr[i] == result[j]) {   
                isRepeated = true;
                break;
            }
        }
        if (!isRepeated) {
            result.push(arr[i]);
        }
    }
    return result;
}

$.ajaxSetup({
    cache:false, //关闭ajax缓存
    error:function(XMLHttpRequest,textStatus){
        if(XMLHttpRequest.status==200){
            return;
        }
        var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus");
        var repText=XMLHttpRequest.responseText;
        var result=jQuery.parseJSON(repText);
        if(sessionstatus=="timeout"){
            $.messager.confirm("温馨提示:",result.msg,function(ret){
                window.location.replace(ret.url);
            },result)
        }else if(XMLHttpRequest.status==403){  //验证不通过
            alert("权限不足");
        }else{
            $.messager.alert("系统错误","请求出错,内部服务器出错");
        }

}
});


var bootstrap = {
	//提示框
	alert : function ( msg,title, callback) {
	    var dialogHTML = '<div id="selfAlert" class="modal fade" >';
		    dialogHTML += 	'<div class="modal-dialog" style="width: 80%; margin: 40% auto;">';
		    dialogHTML += 		'<div class="modal-content">';
		    dialogHTML += 			'<div class="modal-header"  style="border: 0px;">';
		    dialogHTML += 				'<button type="button" class="close" data-dismiss="modal" aria-label="Close">&times;</span></button>';
		    dialogHTML += 				'<h4 class="modal-title">' + (title||'提示') + '</h4>';
		    dialogHTML += 			'</div>';
		    dialogHTML += 			'<div class="modal-body" style="text-align:center;">';
		    dialogHTML += 				msg||'';
		    dialogHTML += 			'</div>';
		    dialogHTML += 			'<div class="modal-footer" style="text-align:center; border:0px;">';
		    dialogHTML += 				'<button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>';
		    dialogHTML += 			'</div>';
		    dialogHTML += 		'</div>';
		    dialogHTML += 	'</div>';
		    dialogHTML += '</div>';

	    if ($('#selfAlert').length <= 0) {
	        $('body').append(dialogHTML);
	    }
	    $('#selfAlert').on('hidden.bs.modal', function () {
	        $('#selfAlert').remove();
	        if (typeof callback == 'function') {
	            callback();
	        }
	    }).modal('show');
	},
	

	
}






